package com.example.myui.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.myui.R;
import com.example.myui.model.MultypeModel;

import java.util.List;


public class MultiAdapter extends BaseMultiItemQuickAdapter<MultypeModel, BaseViewHolder> {
    private Context mContext;
    private List<MultypeModel> mDatas = null;

    public MultiAdapter(Context context, List<MultypeModel> data) {
        super(data);
        this.mContext = context;
        this.mDatas = data;
        Log.i(TAG, "MultiAdapter: " + mDatas.size() + "md" + mDatas.toString());
        addItemType(MultypeModel.TEXT_CONTENT, R.layout.item_type_one);
        addItemType(MultypeModel.TEXT_DES, R.layout.item_type_two);
        addItemType(MultypeModel.TEXT_EMP, R.layout.item_type_three);
    }

    @SuppressLint({"ResourceAsColor", "SetTextI18n"})
    @Override
    protected void convert(BaseViewHolder holder, MultypeModel item) {
        int itemViewType = holder.getItemViewType();
        switch (itemViewType) {
            case MultypeModel.TEXT_CONTENT:
                RecyclerView recyclerview = holder.getView(R.id.recyclerview_scroll);
                LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false) {
                    @Override
                    public boolean canScrollVertically() {
                        return false;
                    }
                };
                recyclerview.setLayoutManager(linearLayoutManager);
                InnerAdapter innerAdapter = new InnerAdapter(mContext, mData.get(holder.getLayoutPosition()).getContent());
                Log.i(TAG, "convert: ");
                recyclerview.setAdapter(innerAdapter);

//                holder.setText(R.id.tv_type_one_content, item.getContent().get(0).getName());
//                holder.setText(R.id.tv_type_one_time, item.getContent().get(0).getTime());
                holder.setText(R.id.tv_des_mid, item.getDes());
//
//                RelativeLayout rl_title = holder.getView(R.id.rl_title);
//                rl_title.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        Log.i(TAG, "onClick: " + "des");
//                    }
//                });
//                TextView experision = holder.getView(R.id.tv_des_mid);
//                experision.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        Log.i(TAG, "onClick: " + "title");
//                        ((Activity) mContext).startActivityForResult(new Intent(mContext, ResultActivity.class), 1001);
//                    }
//                });

                break;
//            case MultypeModel.TEXT_DES:
//                holder.setText(R.id.tv_type_two_content,item.getContent().get(0).getName());
//
//                break;
//            case MultypeModel.TEXT_EMP:
//
//                break;
        }
    }
}
